﻿using System;
using System.Text;
using JKF.BusinessLayer.BLL;
using JKF.Entities.Model;
using JKF.Substructure;

namespace JKF.Web.Customer.EditCustomer
{
    public partial class Change_Shop : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MODULE_NAME_EN = "CUSTOMER";
        }
        private static StringBuilder sbBuilder = new StringBuilder();

        public string CanChangeShop
        {
            get { return CheckAction("更换店铺") ? "true" : "false"; }
        }

        public string CustomerKey
        {
            get { return P("customerKey"); }
        }

        public string CurstomerShopName
        {
            get
            {
                var key = CustomerKey;
                if (key.IsGuidB())
                {
                    var bll = new bllCUSTOMER();
                    var shopbll = new bllSHOP();
                    var mod = bll.GetModel(new Guid(key));
                    if (mod != null)
                    {
                        var shop = shopbll.GetModel(mod.SHOP_CODE);
                        return shop == null ? string.Empty : shop.SHOP_NAME;
                    }
                }
                return "";
            }
        }

        public string ShopOptions
        {
            get
            {
                var bllshop = new bllSHOP();
                sbBuilder.Clear();
                var shops = bllshop.GetListArray(string.Format(" shop_code in (select shop_code from sys_user_shop where user_key='{0}')",
                    bllSYS_USER.CurrentUser.USER_KEY));
                foreach (var shop in shops)
                {
                    sbBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", Server.HtmlEncode(shop.SHOP_CODE), Server.HtmlEncode(shop.SHOP_NAME));
                }
                return sbBuilder.ToString();
            }
        }
    }
}